<template>
	<view class="">
		<view style="margin-bottom: 15px;">
			<uni-card isFull="false">
				<view class="course_head">
					<u-avatar :src="src" style="margin-right: 20px;"></u-avatar>
				</view>
				<view class="course_head">{{stuname}}</view>
			</uni-card>
		</view>
		<u-card :title="title" full="true" show-foot="false">
			<view class="" style="height: 90px;" slot="body" v-for="item in courselist1" :key="item">
				<view class="course_body" style="" @click="tomycourse(item)">
					<view class="course_body_text">
						<view style="">{{item.courseName}}</view>
							<u-line-progress active-color="#2979ff" :percent="item.progress"></u-line-progress>
					</view>
					<image class="course_body_img" :src="item.img" mode="aspectFill"></image>
					
				</view>
			</view>
		</u-card>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				stuid: "",
				stuname: "",
				src: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg',
				title: '在学的课程',
				courselist: [],
				courselist1: [],
				progress: '50'
			}
		},
		onLoad(){
			
		},
		onShow() {
			this.stuid = uni.getStorageSync("stuid");
			this.stuname = uni.getStorageSync("stuname");
			this.getmycourse();
			this.getcount();
		},
		onReady() {
			this.islogin();
		},
		methods: {
			islogin() {
				if (!this.stuid) {
					uni.navigateTo({
						url: "../xiaocong-login/login/login"
					})
				}
			},
			getmycourse() {
				this.$http('/aplication2', {
						studentid: uni.getStorageSync("stuid")
					})
					.then((res) => {
						this.courselist = res;
						console.log(res);
					})
			},
			getcount() {
				this.$http('/getcount', {
						studentid: uni.getStorageSync("stuid")
					})
					.then((res) => {
						this.courselist1 = this.courselist;
						for(let i = 0;i < this.courselist.length;i++)
						{
							this.courselist1[i].progress = res[i]*100;
							console.log(this.courselist1[i])
						}
					})
			},
			tomycourse(even) {
				console.log(even);
				uni.navigateTo({
					url: '../video/video?id=' + even.courseid + '&scid=' + even.scid + '&star=' + even.star
				});
			}
		}
	}
</script>

<style>
	.course_head {
		float: left;
	}

	.course_body{
		position: relative;
		display: flex;
		justify-content: start;
	}
	.course_body_text {
		width: 150px;
		height: 50px;
		display: flex;
		flex-direction: column;
	}

	.course_body_img {
		width: 250rpx;
		height: 190rpx;
		margin-left: 40px;
	}
	.course_body_rate{
		position: absolute;
		top: 100rpx;
	}
</style>
